/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import lt.marsrutai.mobile.android.model.enums.DateTime;
import lt.marsrutai.mobile.android.model.enums.TransportType;
import android.os.Parcel;
import android.os.Parcelable;

public class Segment implements Parcelable {

    private TransportType transportType;
    private String transportId;

    private Calendar startTime;
    private Calendar endTime;

    private String startName;
    private String endName;
    
    private Stop startStop;
    private Stop endStop;

    private String scheduleId;
    private String scheduleName;
    
    private String runId;
    private String trackid;
    
    private List<SegmentPoint> geoPoints = new ArrayList<SegmentPoint>();

    public Segment() {

    }

    private Segment(Parcel in) {
        transportType = TransportType.parseEnum(in.readString());
        transportId = in.readString();

        startTime = new DateTime(in.readLong()).getCalendar();        
        endTime = new DateTime(in.readLong()).getCalendar();        

        startName = in.readString();
        endName = in.readString();

        startStop = in.readParcelable(Stop.class.getClassLoader());
        endStop = in.readParcelable(Stop.class.getClassLoader());

        scheduleId = in.readString();
        scheduleName = in.readString();
        
        runId = in.readString();
        trackid = in.readString();
        
        in.readList(geoPoints, SegmentPoint.class.getClassLoader());
    }

    public static final Parcelable.Creator<Segment> CREATOR = new Parcelable.Creator<Segment>() {

        @Override
        public Segment createFromParcel(Parcel in) {
            return new Segment(in);
        }

        @Override
        public Segment[] newArray(int size) {
            return new Segment[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(transportType.toString());
        dest.writeString(transportId);

        dest.writeLong(startTime.getTimeInMillis());
        dest.writeLong(endTime.getTimeInMillis());

        dest.writeString(startName);
        dest.writeString(endName);

        dest.writeParcelable(startStop, flags);
        dest.writeParcelable(endStop, flags);

        dest.writeString(scheduleId);
        dest.writeString(scheduleName);

        dest.writeString(runId);
        dest.writeString(trackid);

        dest.writeList(geoPoints);
    }

    public TransportType getTransportType() {
        return transportType;
    }

    public void setTransportType(TransportType transportType) {
        this.transportType = transportType;
    }

    public String getTransportId() {
        return transportId;
    }

    public void setTransportId(String transportId) {
        this.transportId = transportId;
    }

    public Calendar getEndTime() {
        return endTime;
    }

    public void setEndTime(Calendar endTime) {
        this.endTime = endTime;
    }

    public String getStartName() {
        return startName;
    }

    public void setStartName(String startName) {
        this.startName = startName;
    }

    public String getEndName() {
        return endName;
    }

    public void setEndName(String endName) {
        this.endName = endName;
    }

    public String getScheduleName() {
        return scheduleName;
    }

    public void setScheduleName(String scheduleName) {
        this.scheduleName = scheduleName;
    }

    public Calendar getStartTime() {
        return startTime;
    }

    public void setStartTime(Calendar startTime) {
        this.startTime = startTime;
    }

    public Stop getStartStop() {
        return startStop;
    }

    public void setStartStop(Stop startStop) {
        this.startStop = startStop;
    }

    public Stop getEndStop() {
        return endStop;
    }

    public void setEndStop(Stop endStop) {
        this.endStop = endStop;
    }

    public String getRunId() {
        return runId;
    }

    public void setRunId(String runId) {
        this.runId = runId;
    }

    public String getScheduleId() {
        return scheduleId;
    }

    public void setScheduleId(String scheduleId) {
        this.scheduleId = scheduleId;
    }

    public String getTrackid() {
        return trackid;
    }

    public void setTrackid(String trackid) {
        this.trackid = trackid;
    }

    public List<SegmentPoint> getGeoPoints() {
        return geoPoints;
    }

    public void setGeoPoints(List<SegmentPoint> geoPoints) {
        this.geoPoints = geoPoints;
    }

}
